package org.un.cava.birdeye.ravis.components{
	
	import flash.events.ContextMenuEvent;
	import flash.events.Event;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	
	import mx.core.UIComponent;
	
	import org.un.cava.birdeye.ravis.components.renderers.RendererIconFactory;
	import org.un.cava.birdeye.ravis.components.renderers.nodes.EffectBaseNodeRenderer;
	import org.un.cava.birdeye.ravis.enhancedGraphLayout.event.VGNodeEvent;
	import org.un.cava.birdeye.ravis.graphLayout.visual.IVisualNode;
	
	/**
	 * This a basic icon itemRenderer for a node. 
	 * Images are sourced by directory path and file name.
	 * Based on icons by Paul Davey aka Mattahan (http://mattahan.deviantart.com/).
	 * All rights reserved. 
	 * */
	public class IconNodeRenderer extends EffectBaseNodeRenderer  {
		
		/**
		 * Default constructor
		 * */
		public function IconNodeRenderer() {
			super();
			this.contextMenu = createContextMenu();
			addMenus();
		}
		
		
		protected function createContextMenu():ContextMenu 
		{
			var contextMenu:ContextMenu = new ContextMenu();
			contextMenu.hideBuiltInItems();
			return contextMenu;	
		}
		
		public function pushContextMenu(menuItem:ContextMenuItem):void{
			this.contextMenu.customItems.push(menuItem);
		}
		
		/**
		 * 添加左击快捷菜单
		 * **/
		private function addMenus():void{
			var detail:ContextMenuItem=new ContextMenuItem("人员详细信息",true,true,true);
			detail.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,showDeatil_Handler);
			pushContextMenu(detail);
			
			var more:ContextMenuItem=new ContextMenuItem("关系图",true,true,true);
			more.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,showMore_Handler);
			//pushContextMenu(more);
		}
		/**
		 * 拓朴关系
		 * **/
		private function showMore_Handler(event:ContextMenuEvent):void{
			var vnode:IVisualNode = data as IVisualNode;
			if ((vnode) && (vnode.vgraph))
			{
				var nodeEvent:VGNodeEvent = new VGNodeEvent("VG_NODE_RIGHT_MENU_MORE");
				nodeEvent.originalEvent = event;
				nodeEvent.node = vnode.node;
				vnode.vgraph.dispatchEvent(nodeEvent);
			}
		}
		/**
		 * 人员详细信息
		 * **/
		private function showDeatil_Handler(event:ContextMenuEvent):void{
			var vnode:IVisualNode = data as IVisualNode;
			if ((vnode) && (vnode.vgraph))
			{
				var nodeEvent:VGNodeEvent = new VGNodeEvent("VG_NODE_RIGHT_MENU_DETAIL");
				nodeEvent.originalEvent = event;
				nodeEvent.node = vnode.node;
				vnode.vgraph.dispatchEvent(nodeEvent);
			}
		}
		/**
		 * @inheritDoc
		 * */
		override protected function initComponent(e:Event):void {
			
			var img:UIComponent;
			
			/* initialize the upper part of the renderer */
			initTopPart();
			
			/* add an icon as specified in the XML, this should
			* be checked */
			img = RendererIconFactory.createIcon(this.data.data.@nodeIcon,32);
			img.toolTip = this.data.data.@name; // needs check
			this.addChild(img);
			
			/* now add the filters to the circle */
			reffects.addDSFilters(img);
			
			/* now the link button */
			initLinkButton();
		}
	}
}